package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author fx
 * @since 2024-08-20
 */
@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService learningLessonService;

    /**
     * 01 根据userId 分页查询我的课程列表 （day02 -- 随堂练习-02）
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> pageQueryMyLessons(PageQuery pageQuery) {
        return learningLessonService.pageQueryMyLessons(pageQuery);
    }

    /**
     * 02 查询用户正在学习的课表 （day02 - 作业 - 01）
     * @param
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询用户正在学习的课程")
    public LearningLessonVO queryCurrentLesson() {
        return learningLessonService.queryCurrentLesson();
    }

    /**
     * 03 根据courseId查询课程的学习状态（day02 - 作业 - 02）
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    @ApiOperation("根据courseId查询课程的学习状态")
    public LearningLessonVO queryLessonById(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.queryLessonById(courseId);
    }

    /**
     * 04 根据courseId删除课程（day02 - 作业 - 03）
     * @param courseId
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("根据courseId删除课程")
    public void deleteCourseFromLesson(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        learningLessonService.deleteCourseFromLesson(null,courseId);
    }

    /**
     * 05 根据courseId查询学习人数（day02 - 作业 - 04）
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 06 根据courseId 查询是否是当前用户课表中的有效课程（day02 - 作业 - 05）
     * 如果用户未登录，返回false
     * 如果用户登录 true 表示有效，false 表示无效
     * @param courseId
     * @return
     *
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("校验当前课程是否已经报名")
    public Long isLessonValid(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.isLessonValid(courseId);
    }

    /**
     * 07 创建学习计划（day03-随堂-03）
     * @param planDTO
     */
    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    //@Valid leanrningPlanDTO中的属性校验
    public void createPlans(@Valid @RequestBody LearningPlanDTO planDTO){
        learningLessonService.createPlans(planDTO);
    }

    /**
     * 08 查询我的学习计划（day03-随堂-04）
     * @param pageQuery
     * @return
     */
    @ApiOperation("查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return learningLessonService.queryMyPlans(pageQuery);
    }




}
